home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / amcfp140.lha / AMCAF_Examples / Iff2Raw.AMOS / Iff2Raw.amosSourceCode
AMOS Source Code  |  1996-01-19  |  3KB  |  111 lines

  1. ' *************************************
  2. ' *                                   *
  3. ' *  AMCAF Iff To Raw Converter V1.0  *
  4. ' *      Written by Chris Hodges      *
  5. ' *                                   *
  6. ' *************************************
  7. '
  8. ' Using this program you can convert an (aga) iff picture into raw format, 
  9. ' which is required for displaying it via the ShowAGAPic procedures. 
  10. '
  11. Screen Open 0,640,256,2,$8000
  12. Curs Off : Flash Off : Paper 0 : Pen 1 : Cls 
  13. F$=Fsel$("","","Select an iff file to convert","")
  14. If F$="" Then End 
  15. Print "Loading "+F$+"..." : Print 
  16. Gosub CHUNKDECODE
  17. Print "Conversion successful."
  18. F$=Fsel$( Extension_8_03E0(F$), Extension_8_02F0(F$)-".iff","Select the base name","of the file to save")
  19. If F$="" Then End 
  20. Print "Saving..."
  21.  Extension_8_0472 F$+".col",8
  22.  Extension_8_0472 F$+".raw",10
  23. Erase All 
  24. End 
  25. CHUNKDECODE:
  26.    Extension_8_0456 F$,9
  27.   ST=Start(9) : LE=Length(9)
  28.   Reserve As Work 8,1024
  29.   CMAP=Start(8)
  30.   If Leek(ST)<> Extension_8_0998("FORM") Then Print "Not an IFF-File!" : Stop 
  31.   If Leek(ST+8)<> Extension_8_0998("ILBM") Then Print "Not an ILBM-File!" : Stop 
  32.   If Leek(ST+4)+8<>LE Then Print "Mangeled IFF-FORM!" : Stop 
  33.   AD=ST+12
  34.   Repeat 
  35.     LCH=Leek(AD+4)
  36.     CHNK=Leek(AD)
  37.     If CHNK= Extension_8_0998("BMHD")
  38.       Print "Found BMHD-Chunk."
  39.       SX=Deek(AD+8)
  40.       SY=Deek(AD+10)
  41.       Print "Width :";SX
  42.       Print "Height:";SY
  43.       PL=Peek(AD+16)
  44.       If PL<>8
  45.         Print "Warning! This picture only uses"; Extension_8_04F8(PL);" colours!"
  46.       Else 
  47.         Print "Planes:";PL
  48.       End If 
  49.       PK=Peek(AD+18)
  50.       Print "Packed: "; Extension_8_16A4("no|rle",PK)
  51.       GX=Deek(AD+24)
  52.       GY=Deek(AD+26)
  53.       Reserve As Work 10,SX*SY
  54.       BMP=Start(10) : BMPSIZE=(SX/8)*SY
  55.       Reserve As Work 11,4096
  56.       TST=Start(11)
  57.     End If 
  58.     If CHNK= Extension_8_0998("CMAP")
  59.       Print "Found colormap..."
  60.       For A=0 To(LCH/3)-1
  61.         Poke CMAP+A*4+1,Peek(AD+8+A*3)
  62.         Poke CMAP+A*4+2,Peek(AD+9+A*3)
  63.         Poke CMAP+A*4+3,Peek(AD+10+A*3)
  64.       Next 
  65.     End If 
  66.     If CHNK= Extension_8_0998("BODY")
  67.       Print "Found BODY... please wait while converting."
  68.       BMPOF=BMP : X=0 : P=0
  69.       If PK
  70.         POS=AD+8
  71.         Repeat 
  72.           CON=Peek(POS) : Inc POS
  73.           If CON<128
  74.             For A=0 To CON
  75.               B=Peek(POS) : Gosub BYTEPUT
  76.               Inc POS
  77.             Next 
  78.           End If 
  79.           If CON>128
  80.             B=Peek(POS) : Inc POS
  81.             For A=0 To 256-CON
  82.               Gosub BYTEPUT
  83.             Next 
  84.           End If 
  85.         Until POS=>AD+8+LCH
  86.         If BMPOF<>BMP+BMPSIZE : FAIL=1 : End If 
  87.       Else 
  88.         For A=0 To LCH-1
  89.           B=Peek(AD+8+A)
  90.           Gosub BYTEPUT
  91.         Next 
  92.       End If 
  93.     End If 
  94.     If LCH and 1 Then Inc AD
  95.     Add AD,LCH+8
  96.   Until AD=>ST+LE
  97.   If FAIL Then Print "Error during conversion! Memory could be corrupt!" : Stop 
  98. Return 
  99. End 
  100. BYTEPUT:
  101.   Poke BMPOF+P*BMPSIZE,B
  102.   Inc BMPOF : Add X,8
  103.   If(X and $FFF8)=>SX
  104.     Inc P : X=0
  105.     If P=>PL
  106.       P=0
  107.     Else 
  108.       Add BMPOF,-SX/8
  109.     End If 
  110.   End If 
  111. Return